using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;

namespace Elementum
{
    class RootStage : Stage
    {
        public RootStage(Game game) : base(game) { }

        float GROUND_ALPHA = 0f;

        public override void InitializeScenes()
        {
            base.InitializeScenes();


            Transition tra;
            //tra = new DefauldTransition(1, 0, 0, 20);
            //tra.Register(this);

            if (GameClass._firstInGame)
            {
                tra = new DefauldTransition(1, 0, 0, 20);
                tra.Register(this);
                tra = new TitleTransition("images/system/title", 0, 1, 15, 120);
                tra.Register(this);
                tra = new TitleTransition("images/system/title", 1, 1, 120, 180);
                tra.Register(this);
                tra = new TitleTransition("images/system/title", 1, 0, 180, 240);
                tra.Register(this);
                GameClass._firstInGame = false;
            }
            else
            {
                tra = new DefauldTransition(1, 0, 0, 60);
                tra.Register(this);
            }

            



            Animation a = new Animation("images/stages/root/root0");
            a.LayerDepth = 0.9f;
            _backGround.Add(a);
            a = new Animation("images/stages/root/root1");
            a.LayerDepth = 0.9f;
            _backGround.Add(a);
            _backGroundPos = new Vector2(-475, -512);
            _scenceBound = new Rectangle(-105, -182,1398, 544);

            camera.Bound = _scenceBound;
           // basePos = player.Position;

            for (int i = 0; i < 3; i++)
            {
                Animation wallBack = new Animation("images/stages/root/stageroot" + i);
                //wallBack.LayerDepth = 0.9f;
                _wallBackGround.Add(wallBack);
            }
            _wallBackGroungPos = new Vector2(-720, -410);

            GroundObject grount;
            ProtalGate protalSwitch;


            grount = new GroundObject(this._world, this); grount.Position = new Vector2(5, 466); grount.CurrentAnimation = new Animation("images/ground/dirtwall", new Point(424, 189)); grount.Size = new Vector2(424, 189); grount.Alpha = GROUND_ALPHA; grount.Rotation = 0f; Actors.Add(grount);

            grount = new GroundObject(this._world, this); grount.Position = new Vector2(481, 413); grount.CurrentAnimation = new Animation("images/ground/dirtwall", new Point(549, 106)); grount.Size = new Vector2(549, 106); grount.Alpha = GROUND_ALPHA; grount.Rotation = 0f; Actors.Add(grount);
            grount = new GroundObject(this._world, this); grount.Position = new Vector2(1123, 413); grount.CurrentAnimation = new Animation("images/ground/dirtwall", new Point(736, 106)); grount.Size = new Vector2(736, 106); grount.Alpha = GROUND_ALPHA; grount.Rotation = 0f; Actors.Add(grount);
            grount = new GroundObject(this._world, this); grount.Position = new Vector2(188, 370); grount.CurrentAnimation = new Animation("images/ground/dirtwall", new Point(303, 103)); grount.Size = new Vector2(303, 103); grount.Alpha = GROUND_ALPHA; grount.Rotation = -0.3f; Actors.Add(grount);
            grount = new GroundObject(this._world, this); grount.Position = new Vector2(-269, 388); grount.CurrentAnimation = new Animation("images/ground/dirtwall", new Point(655, 223)); grount.Size = new Vector2(655, 223); grount.Alpha = GROUND_ALPHA; grount.Rotation = 0f; Actors.Add(grount);
            grount = new GroundObject(this._world, this); grount.Position = new Vector2(-467, 109); grount.CurrentAnimation = new Animation("images/ground/dirtwall", new Point(64, 649)); grount.Size = new Vector2(64, 649); grount.Alpha = GROUND_ALPHA; grount.Rotation = 0f; Actors.Add(grount);
            grount = new GroundObject(this._world, this); grount.Position = new Vector2(1515, 211); grount.CurrentAnimation = new Animation("images/ground/dirtwall", new Point(64, 586)); grount.Size = new Vector2(64, 586); grount.Alpha = GROUND_ALPHA; grount.Rotation = 0f; Actors.Add(grount);
            protalSwitch = new ProtalGate("rootProtal", _world, this); protalSwitch.Position = new Vector2(568, 310); Actors.Add(protalSwitch); protalSwitch.CurrentAnimation = null;
            _startProtal = new ProtalCommand("rootStage", "rootProtal");
            protalSwitch = new ProtalGate("rootProtal2", _world, this); protalSwitch.ProtalCommand = new ProtalCommand("stage0", "Machine_Protal1"); protalSwitch.Position = new Vector2(-21, 226); Actors.Add(protalSwitch);
            protalSwitch = new ProtalGate("rootProtal3", _world, this); protalSwitch.ProtalCommand = new ProtalCommand("stage1", "protal0"); protalSwitch.Position = new Vector2(1100, 311); Actors.Add(protalSwitch);


            _song = MusicManager.LoadSong("Music/stageroot");
            
            if (GameClass._musicString == "Music/stageroot")
            {}
            else 
            {
                GameClass._musicString = "Music/stageroot";
                MediaPlayer.Play(_song);
            }
           // MediaPlayer.Volume = 1f;
            
            MediaPlayer.IsRepeating = true;

        }

        public override void OnDraw(SpriteBatch spriteBatch, int delta)
        {
            base.OnDraw(spriteBatch, delta);

            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, camera.Transform);
           // basePos = player.Position;
            foreach (VisibleObject b in actors)
                b.OnDraw(spriteBatch, camera.Transform);

            spriteBatch.End();

            //spriteBatch.Begin();
            //spriteBatch.DrawString(Font, "" + test, new Vector2(50, 50), Color.Black);
            //spriteBatch.End();

        }

        public override Stage Clone()
        {
            RootStage stage = new RootStage(Game);
            stage.InitializeScenes();
            return stage;
        }
    }
}
